package net.qiqb.ddd.user.application;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.qiqb.core.executing.EntityIdGeneratorHolder;
import net.qiqb.core.executing.annotation.Command;
import net.qiqb.core.executing.annotation.HandleBusiness;
import net.qiqb.core.executing.annotation.ObtainAggregateObject;
import net.qiqb.ddd.user.domain.UserAggregateRoot;
import net.qiqb.execute.UserId;

@Slf4j
@Command(UserAggregateRoot.class)
public class UserCreateCmd {

    @Getter
    private final String name;

    public UserCreateCmd(String name) {
        this.name = name;
    }

    @ObtainAggregateObject
    public UserAggregateRoot obtain() {
        log.info("创建用户聚合根");
        final UserId userId = EntityIdGeneratorHolder.generate(UserId.class);
        return new UserAggregateRoot(userId, name);
    }

    @HandleBusiness
    public void handleBusiness(UserAggregateRoot userEntity) {

        log.info("创建用户聚合根：后处理业务流程.{}", userEntity);
    }
}
